<?php
include_once('./config/config.php');
// 校验用户是否登陆
include_once('./config/check.php');

$page = $_GET['page'] ?? 1;
$limit = 3;
// 偏移量
$start = ($page -1) * $limit;
// 显示页码
$size = 3;
// 总数量
$countsql = "SELECT COUNT(*) as count FROM per_person";
// 查询总数量
$total = find($countsql);

// 分页功能
$pagestr = page($page, $total['count'], $limit, $size);

$sql = "SELECT a.*,b.`name`as depname,c.`name`as jobname FROM per_person as a LEFT JOIN per_department as b ON a.depid = b.id LEFT JOIN per_job as c ON a.jobid = c.id ORDER BY `createtime` DESC LIMIT $start,$limit";

$list = all($sql);

?>
<!DOCTYPE html>
<html lang="en">

<head>
    <?php include_once('common/meta.php');?>
    <!-- 引入分页样式 -->
    <link rel="stylesheet" href="./assets/page/css.css">
</head>

<body>


    <?php include_once('common/header.php'); ?>

    <?php include_once('common/menu.php'); ?>

    <div class="content">
        <div class="header">
            <h1 class="page-title">员工管理</h1>
        </div>
        <ul class="breadcrumb">
            <li><a href="index.php">Home</a> <span class="divider">/</span></li>
            <li class="active">Index</li>
        </ul>

        <div class="container-fluid">
            <div class="row-fluid">
                <div class="btn-toolbar">
                    <button class="btn btn-primary" onClick="location='PersonAdd.php'"><i class="icon-plus"></i>员工</button>
                </div>
                <div class="well">
                    <table class="table">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>用户名</th>
                                <th>头像</th>
                                <th>性别</th>
                                <th>手机号码</th>
                                <th>邮箱</th>
                                <th>所属部门</th>
                                <th>所属职位</th>
                                <th>入职时间</th>
                                <th style="width: 40px;">操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach($list as $item) { ?>
                                <tr>
                                    <td><?php  echo $item['id'] ?></td>
                                    <td><?php  echo $item['name'] ?></td>
                                    <td>
                                        <?php  if($item['avatar']) { ?>
                                            <img src="<?php  echo $item['avatar'] ?>" alt="" style="width: 50px;height: 50px;object-fit: cover;">
                                        <?php } else {?>
                                            <img src="./assets/images/GitHub头像.jpg" alt="" style="width: 50px;height: 50px;object-fit: cover;">
                                        <?php }?>
                                    </td>
                                    <td><?php  if($item['sex'] == 1) {
                                        echo '男';
                                    } else if($item['sex'] == 2) {
                                        echo '女';
                                    } else {
                                        echo '未知';
                                    }
                                    ?></td>
                                    <td><?php  echo $item['mobile'] ?></td>
                                    <td><?php  echo $item['email'] ?></td>
                                    <td><?php  echo $item['depname'] ?></td>
                                    <td><?php  echo $item['jobname'] ?></td>
                                    <td><?php  echo date("Y-m-d",$item['createtime']) ?></td>
                                    <td>
                                        <a href="user.html"><i class="icon-pencil"></i></a>
                                        <a href="#myModal" role="button" data-toggle="modal"><i class="icon-remove"></i></a>
                                    </td>
                                </tr>
                            <?php }?>
                        </tbody>
                    </table>
                </div>

                <div class="pagination">
                    <?php echo $pagestr;?>
                </div>

                <div class="modal small hide fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                        <h3 id="myModalLabel">Delete Confirmation</h3>
                    </div>
                    <div class="modal-body">
                        <p class="error-text"><i class="icon-warning-sign modal-icon"></i>Are you sure you want to delete the user?</p>
                    </div>
                    <div class="modal-footer">
                        <button class="btn" data-dismiss="modal" aria-hidden="true">Cancel</button>
                        <button class="btn btn-danger" data-dismiss="modal">Delete</button>
                    </div>
                </div>

                <?php include_once('common/footer.php'); ?>

            </div>
        </div>
    </div>
</body>
</html>
<?php include_once('common/script.php');?>